<template>
    <div class="query">
        <!-- 高级查询 -->
        <el-dialog title="高级查询" :visible.sync="dialogVisible" width="900px" :close-on-click-modal="false">
            <div v-if="['监管类', '制度解读类'].includes(complianceType) && tabPaneType == 'File'">
                <table>
                    <tr>
                        <td>来源类型：</td>
                        <td>
                            <el-select v-model="indexClauseRequest.directoryCode1" placeholder="请选择" size="mini" clearable filterable>
                                <el-option
                                    :label="item.indexName"
                                    :value="item.indexDirectoryCode"
                                    v-for="item in indexSourceCodeSelect"
                                    :key="item.indexDirectoryCode"
                                    >{{ item.indexName }}</el-option
                                >
                            </el-select>
                        </td>
                        <td>条款状态：</td>
                        <td>
                            <el-select v-model="indexClauseRequest.clauseStatus" placeholder="请选择" size="mini" clearable>
                                <el-option label="启用" value="1"></el-option>
                                <el-option label="停用" value="0"></el-option>
                            </el-select>
                        </td>
                    </tr>
                    <tr>
                        <td>来源名称：</td>
                        <td>
                            <el-select v-model="indexClauseRequest.articleCode1" placeholder="请选择" size="mini" clearable filterable>
                                <el-option
                                    :label="item.articleName"
                                    :value="item.articleCode"
                                    v-for="item in indexSourceCodeSelect1"
                                    :key="item.articleCode"
                                    >{{ item.articleName }}</el-option
                                >
                            </el-select>
                        </td>
                        <td>版本号：</td>
                        <td>
                            <!-- <el-input v-model="indexClauseRequest.versionNumber" placeholder="请输入内容" size="mini"> </el-input> -->
                            <el-select
                                v-model="indexClauseRequest.versionNumbers"
                                placeholder="请选择"
                                size="mini"
                                filterable
                                clearable
                                multiple
                                collapse-tags
                            >
                                <el-option :label="item.dictKeyName" :value="item.dictKey" v-for="item in VersionNums" :key="item.dictKey">
                                    {{ item.dictKeyName }}
                                </el-option>
                            </el-select>
                        </td>
                    </tr>
                    <tr>
                        <td>公募产品：</td>
                        <td>
                            <el-select v-model="indexClauseRequest.pcProductType" placeholder="请选择" size="mini" clearable multiple collapse-tags>
                                <el-option label="股票基金" value="1"></el-option>
                                <el-option label="债券基金" value="2"></el-option>
                                <el-option label="混合基金" value="3"></el-option>
                                <el-option label="货币基金类" value="4"></el-option>
                            </el-select>
                        </td>
                        <td>私募产品：</td>
                        <td>
                            <el-select v-model="indexClauseRequest.ptProductType1" placeholder="请选择" size="mini" clearable multiple collapse-tags>
                                <el-option label="集合" value="A2"></el-option>
                                <el-option label="单一" value="B1"></el-option>
                                <el-option label="固收类" value="A"></el-option>
                                <el-option label="权益类" value="B"></el-option>
                                <el-option label="混合类" value="C"></el-option>
                                <el-option label="金融衍生品类" value="D"></el-option>
                            </el-select>
                        </td>
                    </tr>
                    <tr>
                        <td>特殊产品：</td>
                        <td>
                            <el-select
                                v-model="indexClauseRequest.specialProductsList"
                                placeholder="请选择"
                                multiple
                                collapse-tags
                                size="mini"
                                clearable
                            >
                                <el-option label="QDII" value="QDII"></el-option>
                                <el-option label="FOF" value="FOF"></el-option>
                            </el-select>
                        </td>
                        <td>条款号：</td>
                        <td>
                            <el-input v-model="indexClauseRequest.clauseNo" placeholder="请输入内容" size="mini"> </el-input>
                        </td>
                    </tr>
                    <tr>
                        <td>是否可被动超限：</td>
                        <td>
                            <el-select v-model="indexClauseRequest.passiveTransfinite" placeholder="请选择" size="mini" clearable>
                                <el-option label="是" value="1"></el-option>
                                <el-option label="否" value="0"></el-option>
                            </el-select>
                        </td>
                    </tr>
                    <tr>
                        <td>恒生交易系统支持情况：</td>
                        <td>
                            <el-select v-model="indexClauseRequest.realTimeSupport" placeholder="请选择" size="mini" clearable>
                                <el-option label="支持" value="1"></el-option>
                                <el-option label="部分支持" value="2"></el-option>
                                <el-option label="不支持" value="3"></el-option>
                            </el-select>
                        </td>
                        <td>事后系统支持情况：</td>
                        <td>
                            <el-select v-model="indexClauseRequest.hdSupport" placeholder="请选择" size="mini" clearable>
                                <el-option label="支持" value="1"></el-option>
                                <el-option label="部分支持" value="2"></el-option>
                                <el-option label="不支持" value="3"></el-option>
                            </el-select>
                        </td>
                    </tr>
                </table>
            </div>
            <div v-else-if="complianceType === '合同类' && tabPaneType == 'File'">
                <table>
                    <tr>
                        <td>条款状态：</td>
                        <td>
                            <el-select v-model="indexClauseRequest.clauseStatus" placeholder="请选择" size="mini" clearable>
                                <el-option label="启用" value="1"></el-option>
                                <el-option label="停用" value="0"></el-option>
                            </el-select>
                        </td>
                        <td>条款类型：</td>
                        <td>
                            <el-select v-model="indexClauseRequest.clauseType" placeholder="请选择" size="mini" clearable filterable>
                                <el-option label="投资范围" value="0" key="0"></el-option>
                                <el-option label="投资限制" value="1" key="1"></el-option>
                                <!-- <el-option label="关联交易" value="2" key="2"></el-option> -->
                                <el-option label="其他" value="3" key="3"></el-option>
                                <el-option label="监管条款" value="4"></el-option>
                                <el-option label="预警止损线" value="5"></el-option>
                            </el-select>
                        </td>
                    </tr>
                    <tr>
                        <td>条款适用产品：</td>
                        <td>
                            <el-select v-model="indexClauseRequest.articleCode1" placeholder="请选择" size="mini" clearable filterable>
                                <el-option
                                    :label="item.indexName"
                                    :value="item.indexDirectoryCode"
                                    v-for="item in itemProduct"
                                    :key="item.indexDirectoryCode"
                                    >{{ item.indexName }}</el-option
                                >
                            </el-select>
                        </td>
                        <td>来源类型：</td>
                        <td>
                            <el-select v-model="indexClauseRequest.directoryCode1Str" placeholder="请选择" size="mini" clearable filterable>
                                <el-option label="公募" key="5,8" value="5,8"></el-option>
                                <el-option label="私募单一" key="6,9" value="6,9"></el-option>
                                <el-option label="私募集合" key="7,10" value="7,10"></el-option>
                            </el-select>
                        </td>
                    </tr>
                    <tr>
                        <td>合同名称：</td>
                        <td>
                            <el-select v-model="indexClauseRequest.versionNumbers" placeholder="请选择" size="mini" clearable filterable>
                                <el-option
                                    :label="item.versionNumber"
                                    :value="item.articleDeatilsCode"
                                    v-for="item in articleCodeSelect1"
                                    :key="item.articleDeatilsCode"
                                    >{{ item.versionNumber }}</el-option
                                >
                            </el-select>
                        </td>
                        <td>是否可被动超限：</td>
                        <td>
                            <el-select v-model="indexClauseRequest.passiveTransfinite" placeholder="请选择" size="mini" clearable>
                                <el-option label="是" value="1"></el-option>
                                <el-option label="否" value="0"></el-option>
                            </el-select>
                        </td>
                    </tr>
                    <tr>
                        <td>恒生交易系统支持情况：</td>
                        <td>
                            <el-select v-model="indexClauseRequest.realTimeSupport" placeholder="请选择" size="mini" clearable>
                                <el-option label="支持" value="1"></el-option>
                                <el-option label="部分支持" value="2"></el-option>
                                <el-option label="不支持" value="3"></el-option>
                            </el-select>
                        </td>
                        <td>事后系统支持情况：</td>
                        <td>
                            <el-select v-model="indexClauseRequest.hdSupport" placeholder="请选择" size="mini" clearable>
                                <el-option label="支持" value="1"></el-option>
                                <el-option label="部分支持" value="2"></el-option>
                                <el-option label="不支持" value="3"></el-option>
                            </el-select>
                        </td>
                    </tr>
                </table>
            </div>
            <div v-if="tabPaneType == 'Product'">
                <table>
                    <tr>
                        <td>条款状态：</td>
                        <td>
                            <el-select v-model="indexClauseRequest2.clauseStatus" placeholder="请选择" size="mini" clearable>
                                <el-option label="启用" value="1"></el-option>
                                <el-option label="停用" value="0"></el-option>
                            </el-select>
                        </td>
                        <td>条款类型：</td>
                        <td>
                            <el-select v-model="indexClauseRequest2.clauseType" placeholder="请选择" size="mini" clearable filterable>
                                <el-option label="投资范围" value="0" key="0"></el-option>
                                <el-option label="投资限制" value="1" key="1"></el-option>
                                <!-- <el-option label="关联交易" value="2" key="2"></el-option> -->
                                <el-option label="其他" value="3" key="3"></el-option>
                                <el-option label="监管条款" value="4"></el-option>
                                <el-option label="预警止损线" value="5"></el-option>
                            </el-select>
                        </td>
                    </tr>
                    <tr>
                        <td>条款适用产品：</td>
                        <td>
                            <el-select v-model="indexClauseRequest2.articleCode1" placeholder="请选择" size="mini" clearable filterable>
                                <el-option
                                    :label="item.indexName"
                                    :value="item.indexDirectoryCode"
                                    v-for="item in itemProduct"
                                    :key="item.indexDirectoryCode"
                                    >{{ item.indexName }}</el-option
                                >
                            </el-select>
                        </td>
                        <td>来源类型：</td>
                        <td>
                            <el-select v-model="indexClauseRequest2.directoryCode1Str" placeholder="请选择" size="mini" clearable filterable>
                                <el-option label="公募" key="5,8" value="5,8"></el-option>
                                <el-option label="私募单一" key="6,9" value="6,9"></el-option>
                                <el-option label="私募集合" key="7,10" value="7,10"></el-option>
                            </el-select>
                        </td>
                    </tr>
                    <tr>
                        <td>是否可被动超限：</td>
                        <td>
                            <el-select v-model="indexClauseRequest2.passiveTransfinite" placeholder="请选择" size="mini" clearable>
                                <el-option label="是" value="1"></el-option>
                                <el-option label="否" value="0"></el-option>
                            </el-select>
                        </td>
                    </tr>
                    <tr>
                        <td>恒生交易系统支持情况：</td>
                        <td>
                            <el-select v-model="indexClauseRequest2.realTimeSupport" placeholder="请选择" size="mini" clearable>
                                <el-option label="支持" value="1"></el-option>
                                <el-option label="部分支持" value="2"></el-option>
                                <el-option label="不支持" value="3"></el-option>
                            </el-select>
                        </td>
                        <td>事后系统支持情况：</td>
                        <td>
                            <el-select v-model="indexClauseRequest2.hdSupport" placeholder="请选择" size="mini" clearable>
                                <el-option label="支持" value="1"></el-option>
                                <el-option label="部分支持" value="2"></el-option>
                                <el-option label="不支持" value="3"></el-option>
                            </el-select>
                        </td>
                    </tr>
                </table>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="handleClauseQuery('cancel')">取 消</el-button>
                <el-button @click="handleClauseQuery('reset')">重 置</el-button>
                <el-button type="primary" @click="handleClauseQuery('confirm')">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>
<script lang="ts">
import { Component, Vue, Prop, Watch } from 'vue-property-decorator';
@Component({
    name: 'ClauseQueryDialog',
    components: {},
})
export default class ClauseQueryDialog extends Vue {
    @Prop() clauseQueryDialog?;
    @Prop() treeNodeData;
    @Prop() treeNodeDataProduct;
    @Prop() clauseQueryParam?;
    @Prop() clauseQueryParamPro?;
    @Prop() complianceType;
    // @Prop() indexClauseList; // 条款号下拉框数据
    @Prop() tabPaneType; // File    Product
    @Prop() directoryCodeSelect; // 产品维度、高级查询。来源类型
    @Prop() allProduct; // 条款适用产品所有
    private dialogVisible: boolean = false;
    private clauseCodeSelect = []; // 条款编号下拉数据
    private clauseNoSelect = []; // 条款号下拉数据
    private clauseTextSelect = []; // 条款原文下拉数据
    private indexSourceCodeSelect = []; // 来源类型
    private indexSourceCodeSelect1 = []; // 来源名称
    private articleCodeSelect1 = []; // 合同名称
    private allProductSelect = []; // 条款适用产品下拉框
    private queryList = {
        type: '',
    };
    indexClauseRequest = {
        // directoryCode: '', // 条款序号
        directoryCode1: '', // 条款序号
        clauseStatus: '', // 条款状态
        clauseText: '', // 条款原文
        // articleCode: '', // 来源名称
        articleCode1: '', // 来源名称
        versionNumbers: [], // 版本号
        clauseNo: '', // 条款号
        versionValid: '', // 版本是否有效
        suitableFund: '', // 条款适用产品
        passiveTransfinite: '', // 是否可被动超限
        realTimeSupport: '', // 恒生交易系统是否支持
        hdSupport: '', // 事后系统能否支持
        pcProductType: [], // 公募产品
        ptProductType1: [], // 私募产品
        clauseType: '', // 条款类型
        directoryCode1Str: '', // 来源类型--产品
        hsSupport: '',
        shSupport: '',
        specialProductsList: []
    };
    indexClauseRequest2 = {
        // directoryCode: '', // 条款序号
        directoryCode1Str: '', // 条款序号
        clauseStatus: '', // 条款状态
        clauseText: '', // 条款原文
        // articleCode: '', // 来源名称
        articleCode1: '', // 来源名称
        versionNumbers: [], // 版本号
        clauseNo: '', // 条款号
        versionValid: '', // 版本是否有效
        suitableFund: '', // 条款适用产品
        passiveTransfinite: '', // 是否可被动超限
        realTimeSupport: '', // 恒生交易系统是否支持
        hdSupport: '', // 事后系统能否支持
        pcProductType: [], // 公募产品
        ptProductType1: [], // 私募产品
        clauseType: '', // 条款类型
        hsSupport: '',
        shSupport: '',
    };
    indexClauseList = [];
    itemProduct = []; // 条款适用产品
    private VersionNums = [];

    @Watch('clauseQueryDialog')
    watchClauseQueryDialog(val) {
        this.dialogVisible = val;
        if (this.clauseQueryParam) {
            this.indexClauseRequest = { ...this.clauseQueryParam };
        }
        if (this.clauseQueryParamPro) {
            this.indexClauseRequest2 = { ...this.clauseQueryParamPro };
        }
        if (val == true) {
            if (this.tabPaneType == 'File') {
                this.getIndexSourceSelect1();
                this.getIndexSourceSelect();
                if (this.treeNodeData.indexType == '2') {
                    this.getArticleSelect1();
                    this.getProduct();
                } else if (this.treeNodeData.indexType != '2') {
                    this.getIndexClauseList();
                }
                console.log(this.treeNodeData, 'this.treeNodeData');

                this.getVersionNums(this.treeNodeData.indexType);
            }
            if (this.tabPaneType == 'Product') {
                this.setProductSelect();
                this.getProduct();
            }
        } else {
        }
    }
    setProductSelect() {
        this.allProductSelect = [];
        if (this.treeNodeDataProduct.id == '3') {
            this.allProduct.forEach(item => {
                if (item.liquidation == '1') {
                    this.allProductSelect.push(item);
                }
            });
        } else if (this.treeNodeDataProduct.id == '4') {
            this.allProduct.forEach(item => {
                if (item.liquidation == '2') {
                    this.allProductSelect.push(item);
                }
            });
        } else if (this.treeNodeDataProduct.id == '5') {
            this.allProduct.forEach(item => {
                if (item.productTypes == '5' && item.liquidation == '1') {
                    this.allProductSelect.push(item);
                }
            });
        } else if (this.treeNodeDataProduct.id == '6') {
            this.allProduct.forEach(item => {
                if (item.productTypes == '6' && item.liquidation == '1') {
                    this.allProductSelect.push(item);
                }
            });
        } else if (this.treeNodeDataProduct.id == '7') {
            this.allProduct.forEach(item => {
                if (item.productTypes == '7' && item.liquidation == '1') {
                    this.allProductSelect.push(item);
                }
            });
        } else if (this.treeNodeDataProduct.id == '8') {
            this.allProduct.forEach(item => {
                if (item.productTypes == '8' && item.liquidation == '2') {
                    this.allProductSelect.push(item);
                }
            });
        } else if (this.treeNodeDataProduct.id == '9') {
            this.allProduct.forEach(item => {
                if (item.productTypes == '9' && item.liquidation == '2') {
                    this.allProductSelect.push(item);
                }
            });
        } else if (this.treeNodeDataProduct.id == '10') {
            this.allProduct.forEach(item => {
                if (item.productTypes == '10' && item.liquidation == '2') {
                    this.allProductSelect.push(item);
                }
            });
        }
    }
    @Watch('tabPaneType', { immediate: true, deep: true })
    watchTabPaneType() {
        this.indexClauseRequest = {
            // directoryCode: '', // 条款序号
            directoryCode1: '', // 条款序号
            clauseStatus: '', // 条款状态
            clauseText: '', // 条款原文
            // articleCode: '', // 来源名称
            articleCode1: '', // 来源名称
            versionNumbers: [], // 版本号
            clauseNo: '', // 条款号
            versionValid: '', // 版本是否有效
            suitableFund: '', // 条款适用产品
            passiveTransfinite: '', // 是否可被动超限
            realTimeSupport: '', // 恒生交易系统是否支持
            hdSupport: '', // 事后系统能否支持
            pcProductType: [], // 公募产品
            ptProductType1: [], // 私募产品
            clauseType: '', // 条款类型
            directoryCode1Str: '', // 来源类型--产品
            hsSupport: '',
            shSupport: '',
            specialProductsList: []
        };
    }
    @Watch('dialogVisible')
    watchDialogVisible(val) {
        if (val == false) {
            this.$emit('emitClauseQuery', false, '');
            this.$emit('emitClauseQueryProduct', false, '');
        }
    }

    // 获取当前来源的所有版本号
    getVersionNums(node) {
        this.$axios
            .post('/zhiguan/indexArticle/articleDetails/query', {
                // articleCode: '',
                indexType: node,
            })
            .then((res: any) => {
                this.VersionNums = [];
                res.forEach(item => this.VersionNums.push({ dictKey: item.articleDeatilsCode, dictKeyName: item.versionNumber }));
            });
    }

    // 条目来源分类下拉-三级
    getIndexSourceSelect() {
        if (this.treeNodeData.indexType != '2') {
            let parentCode = '';
            if (this.treeNodeData.level == '1') {
                parentCode = this.treeNodeData.id;
            } else {
                parentCode = this.treeNodeData.parentCode;
            }
            this.$axios.post('/zhiguan/indexArticle/directory/query', { parentCode: parentCode }).then((res: any) => {
                if (res) {
                    this.indexSourceCodeSelect = [];
                    if (this.treeNodeData.indexType == '1') {
                        res.forEach(item => {
                            if (item.indexType == '1') {
                                this.indexSourceCodeSelect.push(item);
                            }
                        });
                    } else if (this.treeNodeData.indexType == '3') {
                        res.forEach(item => {
                            if (item.indexType == '3') {
                                this.indexSourceCodeSelect.push(item);
                            }
                        });
                    }
                }
            });
        }
    }
    // 条款号下拉框
    getIndexClauseList() {
        this.$axios
            .post('/zhiguan/indexClause/list', {
                indexType: this.clauseQueryParam.indexType,
                directoryCode: this.clauseQueryParam.directoryCode,
                articleCode: this.clauseQueryParam.articleCode,
                liquidation: this.clauseQueryParam.liquidation,
            })
            .then((res: any) => {
                if (res) {
                    this.indexClauseList = [];
                    res.list.forEach(item => this.indexClauseList.push(item));
                }
            });
    }
    // 条款适用产品
    getProduct() {
        this.$axios.post('/zhiguan/indexArticle/directory/product/query', { parentCode: '', indexType: '2' }).then((res: any) => {
            if (res) {
                this.itemProduct = [];
                res.forEach(item => this.itemProduct.push(item));
            }
        });
    }
    // 来源名称下拉
    getIndexSourceSelect1() {
        let data = { indexType: this.treeNodeData.indexType };
        this.$axios.post('/zhiguan/indexArticle/article/query', { ...data }).then((res: any) => {
            this.indexSourceCodeSelect1 = [];
            res.forEach(item => this.indexSourceCodeSelect1.push(item));
        });
    }
    // 合同名称下拉
    getArticleSelect1() {
        let data = {};
        this.$axios.post('/zhiguan/indexArticle/articleDetails/query', { indexType: '2' }).then((res: any) => {
            this.articleCodeSelect1 = [];
            res.forEach(item => this.articleCodeSelect1.push(item));
        });
    }
    // 获取条款编号下拉数据
    getClauseCodeSelect() {
        this.$axios
            .post('/indexClause/clauseCodeSelect', {
                clauseSourceCode: this.treeNodeData.id,
            })
            .then((res: any) => {
                this.clauseCodeSelect = [];
                if (res) {
                    res.forEach(item => this.clauseCodeSelect.push(item));
                }
            });
    }
    // 获取条款号下拉数据
    getClauseNoSelect() {
        this.$axios
            .post('/indexClause/clauseNoSelect', {
                clauseSourceCode: this.treeNodeData.id,
            })
            .then((res: any) => {
                this.clauseNoSelect = [];
                if (res) {
                    res.forEach(item => this.clauseNoSelect.push(item));
                }
            });
    }
    // 获取条款原文下拉数据
    getClauseTextSelect() {
        this.$axios
            .post('/indexClause/clauseTextSelect', {
                clauseSourceCode: this.treeNodeData.id,
            })
            .then((res: any) => {
                this.clauseTextSelect = [];
                if (res) {
                    res.forEach(item => this.clauseTextSelect.push(item));
                }
            });
    }
    handleClauseQuery(parameter) {
        if (parameter == 'cancel') {
            // this.$emit('emitClauseQuery', false, '');
            this.dialogVisible = false;
        } else if (parameter == 'confirm') {
            if (this.tabPaneType == 'File') {
                this.$emit('emitClauseQuery', false, this.indexClauseRequest);
            } else if (this.tabPaneType == 'Product') {
                this.$emit('emitClauseQueryProduct', false, this.indexClauseRequest2);
            }
        } else if (parameter == 'reset') {
            if (this.tabPaneType == 'File') {
                this.indexClauseRequest = {
                    directoryCode1: '', // 条款序号
                    clauseStatus: '', // 条款状态
                    clauseText: '', // 条款原文
                    articleCode1: '', // 来源名称
                    versionNumbers: [], // 版本号
                    clauseNo: '', // 条款号
                    versionValid: '', // 版本是否有效
                    suitableFund: '', // 条款适用产品
                    passiveTransfinite: null, // 是否可被动超限
                    realTimeSupport: '', // 恒生交易系统是否支持
                    hdSupport: '', // 事后系统能否支持
                    pcProductType: [], // 公募产品
                    ptProductType1: [], // 私募产品
                    clauseType: '', // 条款类型
                    directoryCode1Str: '', // 来源类型--产品
                    hsSupport: '',
                    shSupport: '',
                    specialProductsList: []
                };
            } else if (this.tabPaneType == 'Product') {
                this.indexClauseRequest2 = {
                    directoryCode1Str: '', // 条款序号
                    clauseStatus: '', // 条款状态
                    clauseText: '', // 条款原文
                    articleCode1: '', // 来源名称
                    versionNumbers: [], // 版本号
                    clauseNo: '', // 条款号
                    versionValid: '', // 版本是否有效
                    suitableFund: '', // 条款适用产品
                    passiveTransfinite: null, // 是否可被动超限
                    realTimeSupport: '', // 恒生交易系统是否支持
                    hdSupport: '', // 事后系统能否支持
                    pcProductType: [], // 公募产品
                    ptProductType1: [], // 私募产品
                    clauseType: '', // 条款类型
                    hsSupport: '',
                    shSupport: '',
                };
            }
        }
    }
}
</script>
<style lang="scss" scoped>
.query {
    // height: calc(98vh - 7px);
    background: #ffffff;
}
table {
    border-spacing: 10px;
    tr {
        td:nth-child(1),
        td:nth-child(3) {
            text-align: right;
            width: 160px !important;
            font-size: 12px;
        }
    }
}
</style>
